﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>附件</title>
    <meta charset="UTF-8" />
    <base target="_self" />
    <script src="../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../Scripts/config.js" type="text/javascript"></script>
    <script src="../Comm/Gener.js" type="text/javascript"></script>
    <script src="../Scripts/slideBox/jquery.slideBox.min.js" type="text/javascript"></script>
    <script src="Ath.js" type="text/javascript"></script>
    <script src="../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../Comm/JS/Calendar/WdatePicker.js" type="text/javascript" defer="defer"></script>
    <script src="../Scripts/Jquery-plug/fileupload/jquery.uploadify.min.js" type="text/javascript"></script>
    <!-- <link href="../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />-->
    <script src="../Admin/CCFlowEnum.js" type="text/javascript"></script>
    <link href='../Scripts/Jquery-plug/fileupload/uploadify.css' rel='stylesheet' type='text/css' />
    <link href="../Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.css" rel="stylesheet"
        type="text/css" />
    <script src="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/locale/bootstrap-table-zh-CN.js"
        type="text/javascript"></script>
    <!-- 导入可以扩展的按钮事件. -->
    <script src="../../DataUser/OverrideFiles/Ath.js" type="text/javascript"></script>
    <style type="text/css">
        .table > thead > tr > td, .table > tbody > tr > td
        {
            border: 1px solid #ddd;
        }
        .table > thead > tr > th
        {
            border-bottom: 1px solid #ddd;
        }
    </style>
    <script language="javascript" type="text/javascript">

        var numOfUpload = 0;  //要求上传的数量.
        var numOfAths = 0;    //附件数量.
        function CanEditor(fileType) {

            //var fileTypes = BP.Sys.SystemConfig.AppSettings["OpenTypes"];

            var fileTypes = "";
            if (fileTypes == null || fileTypes == "")
                fileTypes = "doc,docx,pdf,xls,xlsx,txt";

            if (fileTypes.indexOf(fileType.toLowerCase()) != -1)
                return true;
            else
                return false;
        }
        function IsImgExt(ext) {
            ext = ext.replace(".", "").toLowerCase();
            switch (ext) {
                case "gif":
                case "jpg":
                case "jepg":
                case "jpeg":
                case "bmp":
                case "png":
                case "tif":
                case "gsp":
                case "mov":
                case "psd":
                case "tiff":
                case "wmf":
                    return true;
                default:
                    return false;
            }
        }

        function GetSortLenth_FromDB(sort, dbs) {
            var sortLength = 0;
            for (var p = 0; p < dbs.length; p++) {
                if (dbs[p].Sort == sort) sortLength++;
            }
            return sortLength;
        }

        var Ath;
        var FK_MapData;
        var FK_FrmAttachment;
        var WorkID;
        var FK_Node;
        var PKVal;
        var IsReadonly;
        var FID;
        var EnsName;
        var FK_Flow;
        //页面启动函数.
        var WebUser = new WebUser();
        var data;


        //检查上传的附件数量是否符合要求
        function CheckAthNum() {
            if (numOfUpload > numOfAths) {
                alert("您至少要上传[" + numOfUpload + "]个附件.");
                return false;
            }
            return true;
        }

        $(function () {

            Ath = GetQueryString("Ath");
            FK_MapData = GetQueryString("FK_MapData");
            FK_FrmAttachment = GetQueryString("FK_FrmAttachment");
            PKVal = GetQueryString("PKVal");
            FK_Node = GetQueryString("FK_Node");
            WorkID = GetQueryString("WorkID");
            IsReadonly = GetQueryString("IsReadonly");
            FID = GetQueryString("FID");
            EnsName = GetQueryString("EnsName");
            FK_Flow = GetQueryString("FK_Flow");

            if (WorkID == "undefined" || WorkID == null || WorkID == "")
                WorkID = GetQueryString("OID");
            if (WorkID == "undefined" || WorkID == null || WorkID == "")
                WorkID = GetQueryString("PKVal");

            //关闭上传进度条
            if (GetQueryString('IsExtend') != undefined && GetQueryString('IsExtend') == "1") {
                $('#bar').css('display', 'block');
                $('#btn_Colse').bind('click', close);
            }
            $('#btn_Colse').bind('click', close);

            //获取上传附件列表的信息及权限信息
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_CCForm");
            handler.AddUrlData();
            data = handler.DoMethodReturnString("Ath_Init");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            if (data.indexOf('url@') == 0) {
                var url = data.replace('url@', '');
                window.location.href = url;
                return;
            }

            data = JSON.parse(data);

            var athDesc = data["AthDesc"][0];

            //自定义表单模式.
            if (athDesc.AthRunModel == 2) {
                src = "../../DataUser/OverrideFiles/AthSelf.htm?PKVal=" + GetPKVal() + "&Ath=" + athDesc.NoOfObj + "&FK_MapData=" + athDesc.FK_MapData + "&FK_FrmAttachment=" + athDesc.MyPK;
                window.location.href = src;
                return;
            }

            var dbs = data["DBAths"];

            var fileShowWay = athDesc.FileShowWay;
            if (fileShowWay == "undefined" || fileShowWay == null || fileShowWay == "")
                fileShowWay = 0;

            //用于必须上传的校验.
            numOfUpload = athDesc.NumOfUpload; //最低上传的数量.
            numOfAths = dbs.length; //现有的数量.

            var mapAttrs = null;

            if (athDesc.IsExpCol != 0) {
                mapAttrs = new Entities("BP.Sys.MapAttrs");
                // ND26501_Ath1
                var extMapData = GetQueryString("FromFrm") + "_Ath1";
                mapAttrs.Retrieve("FK_MapData", extMapData);

                //  alert(extMapData);
                //  alert(mapAttrs.length);
            }


            //表格方式
            if (fileShowWay == FileShowWay.Table)
                FileShowWayTable(athDesc, dbs, mapAttrs);

            //文件上传
            var url = "";
            if (plant == 'CCFlow')
                url = '/WF/CCForm/Handler.ashx?AttachPK=' + FK_FrmAttachment + '&DoType=MoreAttach&EnsName=' + EnsName + '&FK_Flow=' + FK_Flow + '&PKVal=' + PKVal;
            else {
                var currentPath = window.document.location.href;
                var path = currentPath.substring(0, currentPath.indexOf('/WF') + 1);
                url = path + "WF/Ath/AttachmentUpload.do?FK_FrmAttachment=" + FK_FrmAttachment + '&FK_Flow=' + FK_Flow + "&PKVal=" + PKVal;
            }
            url += "&WorkID=" + GetQueryString("WorkID");
            url += "&FID=" + GetQueryString("FID");
            url += "&FK_Node=" + GetQueryString("FK_Node");
            url += "&PWorkID=" + GetQueryString("PWorkID");
            url += "&FK_MapData=" + GetQueryString("FK_MapData");


            if (athDesc.IsExpCol == 0) {
                $('#uploadfile').uploadify({
                    'swf': '../Scripts/Jquery-plug/fileupload/uploadify.swf?',
                    'uploader': url,
                    'auto': true,
                    'fileTypeDesc': '请选择上传文件',
                    'buttonText': '批量上传',
                    'width': 60,
                    'fileTypeExts': realFileExts,
                    'height': 15,
                    'multi': true,
                    'queueSizeLimit': 999,
                    'onUploadStart': function (file) {
                        //获取分组
                        var sort = $("#Sort").val();
                        if (sort != null && sort != "" && sort != undefined)
                            $('#uploadfile').uploadify('settings', 'formData', { "parasData": "Sort=" + sort });
                    },
                    'onQueueComplete': function (queueData) {
                        window.location.href = window.location.href;

                    },
                    'removeCompleted': false
                });
            }
            if (athDesc.IsExpCol == 1) {
                var parasData = "";
                $('#uploadfile').uploadify({
                    'swf': '../Scripts/Jquery-plug/fileupload/uploadify.swf?',
                    'uploader': url,
                    'method': 'GET',
                    'auto': false,
                    'fileTypeDesc': '请选择上传文件',
                    'buttonText': '批量上传',
                    'width': 60,
                    'fileTypeExts': realFileExts,
                    'height': 15,
                    'multi': false,
                    'formData': { "parasData": parasData },
                    'queueSizeLimit': 999,
                    'onUploadStart': function (file) {
                        parasData = $("form").serialize();
                        parasData = decodeURIComponent(parasData, true);
                        parasData = parasData.replace(/&/g, '@');
                        parasData = parasData.replace(/TB_/g, '');
                        parasData = parasData.replace(/RB_/g, '');
                        parasData = parasData.replace(/CB_/g, '');
                        parasData = parasData.replace(/DDL_/g, '');
                        //获取分组
                        var sort = $("#Sort").val();
                        if (sort != null && sort != "" && sort != undefined)
                            parasData += "@Sort=" + sort;

                        $('#uploadfile').uploadify('settings', 'formData', { "parasData": parasData });

                    },
                    'onQueueComplete': function (queueData) {
                        window.location.href = window.location.href;

                    },
                    'removeCompleted': false
                });
            }


        });


        //检查上传附件的数量,如果不符合最低要求alert错误，并且返回false.
        function CheckNumOfUpload() {
            if (numOfUpload > numOfAths) {
                alert('您至少需要上传["+numOfUpload+"]个附件');
                return false;
            }
            return true;
        }

        //Table模式
        var columnNum = 6;
        function FileShowWayTable(athDesc, dbs, mapAttrs) {
            //var html = "<table class='table' >";
            var html = "";
            html += "<thead>";
            var colgroup = "<colgroup>";
            if (athDesc.IsShowTitle == 1) {
                //background-color: #f9f9f9;
                html += "<tr style='border:0px;'>";

                html += "<th  style='width:50px; border: 1px solid #ddd' nowrap=true >序</td>";
                colgroup += "<col width='50px'></col>";
                if (athDesc.Sort != null && athDesc.Sort.indexOf(",") != -1) {
                    var sortColumn = athDesc.Sort.indexOf("@") != -1 ? athDesc.Sort.substring(0, athDesc.Sort.indexOf("@")) : "类别";
                    if (sortColumn == "")
                        sortColumn = "类别";
                    html += "<th style=' border-top: 1px solid #ddd;width:120px' nowrap=true >" + sortColumn + "</td>";
                    colgroup += "<col width='120px'></col>";
                }
                colgroup += "<col width='200px'></col>";
                colgroup += "<col width='50px'></col>";
                colgroup += "<col width='120px'></col>";
                colgroup += "<col width='80px'></col>";
                //是否启用附件从表 0 禁用 1启用
                if (athDesc.IsExpCol == 0) {

                    html += "<th style='min-width:200px; border: 1px solid #ddd' nowrap=true >文件名</th>";
                    html += "<th  style='width:50px; border: 1px solid #ddd' nowrap=true >大小KB</th>";
                    html += "<th  style='width:120px; border: 1px solid #ddd' nowrap=true >上传时间</th>";
                    html += "<th  style='width:80px; border: 1px solid #ddd' nowrap=true >上传人</th>";
                    //html += "<td class='TitleExt' nowrap=true style='width:50px;' >";
                } else {
                    html += "<th nowrap=true style='border: 1px solid #ddd;width:200px' >文件名</th>";
                    html += "<th nowrap=true style='border: 1px solid #ddd;width:50px' >大小KB</th>";
                    html += "<th nowrap=true style='border: 1px solid #ddd;width:120px' >上传时间</th>";
                    html += "<th nowrap=true style='border: 1px solid #ddd;width:80px' >上传人</th>";


                    for (var ii = 0; ii < mapAttrs.length; ii++) {
                        var attr = mapAttrs[ii];
                        if (attr.UIIsInput == 1 && attr.UIIsEnable == 1)
                            html += "<th nowrap=true ><span style='color:red' class='mustInput' data-keyofen='" + attr.KeyOfEn + "' >*</span>";
                        else
                            html += "<th nowrap=true >";
                        if (attr.UIContralType == 0)
                            html += "<label for='TB_" + attr.KeyOfEn + "' class='" + (attr.UIIsInput == 1 ? "mustInput" : "") + "' >" + attr.Name + "</label></th>";

                        if (attr.UIContralType == 1)
                            html += "<label for='DDL_" + attr.KeyOfEn + "' class='" + (attr.UIIsInput == 1 ? "mustInput" : "") + "' >" + attr.Name + "</label></th>";
                        if (attr.UIContralType == 2)
                            html += "<label for='TB_" + attr.KeyOfEn + "' class='" + (attr.UIIsInput == 1 ? "mustInput" : "") + "'  >" + attr.Name + "</label></th>";
                        //
                        if (attr.UIContralType == 3)
                            html += "<label for='RB_" + attr.KeyOfEn + "' class='" + (attr.UIIsInput == 1 ? "mustInput" : "") + "'  >" + attr.Name + "</label></th>";

                    }
                    columnNum = columnNum + mapAttrs.length;
                }
                colgroup += "<col width='50px'></col>";
                html += "<th  nowrap=true style=' border: 1px solid #ddd;width:50px' >";

                if (athDesc.IsDownload == 1 && dbs.length > 0)
                    html += "<a href='javascript:DownZip()' ><img src='../Img/FileType/zip.png' style='width:16px;height:16px;' alt='打包下载' /></a>";
                else
                    html += "操作";

                html += "</th>";
                html += "</thead>";
            }

            html += "<tbody>";
            var i = 0;
            var fileSorts = new Array("");
            var haveAuthSort = false;
            var bSort_Add_TD = false;

            //存在分組
            if (athDesc.Sort != null) {
                haveAuthSort = true;
                //追加一个空项
                if (athDesc.Sort.lastIndexOf(",") + 1 != athDesc.Sort.length)
                    athDesc.Sort = athDesc.Sort + ",";
                fileSorts = athDesc.Sort.split(',');
            }

            //循环分组
            var haveFileSort = "";
            for (var j = 0; j < fileSorts.length; j++) {
                //判断分组是否有文件
                var IsExistFile = false;

                var sort = fileSorts[j]
                if (fileSorts.length > 1 && sort == "")
                    continue;
                bSort_Add_TD = true;

                var mysort = sort;
                if (sort.indexOf("@") != -1)
                    mysort = sort.substring(sort.indexOf('@') + 1);

                for (var k = 0; k < dbs.length; k++) {
                    var db = dbs[k];
                    if (haveAuthSort == true && db.Sort != mysort)
                        continue;
                    IsExistFile = true;
                    haveFileSort += db.Sort + ",";
                    i++;
                    html += "<tr>";
                    html += "<td class='Idx' nowrap>" + i + "</td>";
                    if (athDesc.Sort != null && athDesc.Sort.indexOf(",") != -1) {
                        if (bSort_Add_TD == true) {
                            bSort_Add_TD = false;
                            var rowSpan = GetSortLenth_FromDB(mysort, dbs);
                            html += "<td rowspan=" + rowSpan + ">" + db.Sort + "</td>";
                        }
                    }
                    if (athDesc.IsDownload == 1) {
                        if (athDesc.IsWoEnableWF && CanEditor(db.FileExts))
                            html += addTdTitle(db.FileName, "<a href=\"javascript:Down2018('" + FK_FrmAttachment + "','" + PKVal + "','" + db.MyPK + "')\"><img src='../Img/FileType/" + db.FileExts + ".gif' border=0 onerror=\"src='../Img/FileType/Undefined.gif'\" />" + db.FileName + "</a>");
                        else if (IsImgExt(db.FileExts) == true)
                            html += addTdTitle(db.FileName, "<a href=\"javascript:Down2018('" + FK_FrmAttachment + "','" + PKVal + "','" + db.MyPK + "')\"><img src='../Img/FileType/" + db.FileExts + ".gif' border=0 onerror=\"src='../Img/FileType/Undefined.gif'\" />" + db.FileName + "</a>");
                        else
                            html += addTdTitle(db.FileName, "<a href=\"javascript:Down2018('" + FK_FrmAttachment + "','" + PKVal + "','" + db.MyPK + "');\" ><img src='../Img/FileType/" + db.FileExts + ".gif' border=0 onerror=\"src='../Img/FileType/Undefined.gif'\" />" + db.FileName + "</a>");
                    }
                    else
                        html += "<td><img src='../Img/FileType/" + db.FileExts + ".gif' border=0 onerror=\"src='../Img/FileType/Undefined.gif'\" />" + db.FileName + "</td>";

                    html += "<td>" + db.FileSize + "</td>";
                    html += "<td>" + db.RDT + "</td>";
                    html += "<td>" + db.RecName + "</td>";

                    //如果有数据,就要解析它附件属性.
                    if (athDesc.IsExpCol == 1) {


                        for (var ii = 0; ii < mapAttrs.length; ii++) {
                            var mapAttr = mapAttrs[ii];
                            var defVal = GetPara(mapAttr.KeyOfEn, db.AtPara);
                            if (mapAttr.MyDataType == 2 && mapAttr.LGType == 1) {
                                var senum = new Entity("BP.Sys.SysEnum", mapAttr.UIBindKey + "_CH" + "_" + defVal);
                                defVal = senum.Lab;
                            }
                            if (mapAttr.MyDataType == 4) {
                                if (defVal == "on") defVal = "是";
                                else defVal = "否";
                            }

                            html += "<td>" + defVal + "</td>";
                            //html += "<td></td>";
                        }
                    }
                    //输出操作部分.
                    html += "<td>";
                    if (athDesc.IsDownload == 1)
                        html += "<a href=\"javascript:Down2018('" + FK_FrmAttachment + "','" + PKVal + "','" + db.MyPK + "')\">下载</a>";
                    if (IsReadonly != "1") {
                        var op = "";

                        if (athDesc.DeleteWay == AthDeleteWay.DelAll)//删除所有
                            op = "&nbsp;&nbsp;&nbsp;<a href=\"javascript:Del('" + FK_FrmAttachment + "','" + PKVal + "','" + db.MyPK + "')\">删除</a>";
                        if (athDesc.DeleteWay == AthDeleteWay.DelSelf)//删除自己上传的
                            if (db.Rec == WebUser.No)
                                op = "&nbsp;&nbsp;&nbsp;<a href=\"javascript:Del('" + FK_FrmAttachment + "','" + PKVal + "','" + db.MyPK + "')\">删除</a>";

                        html += op;
                    }

                    html += "</td>";

                    html += "</tr>";
                }

                if (IsExistFile == false) {
                    i++;
                    //组合Html
                    html += "<tr>";
                    html += "<td class='Idx' nowrap>" + i + "</td>";
                    if (fileSorts.length > 1)
                        html += "<td>" + sort + "</td>";
                    html += "<td style='width:100px;color:red'>请上传附件..</td>";
                    html += "<td>&nbsp&nbsp</td>";
                    html += "<td>&nbsp&nbsp</td>";
                    html += "<td>&nbsp&nbsp</td>";
                    //如果有数据,就要解析它附件属性.
                    if (athDesc.IsExpCol == 1) {

                        for (var ii = 0; ii < mapAttrs.length; ii++) {

                            html += "<td>" + InitAthMapAttrOfCtrlFool("", mapAttrs[ii]) + "</td>";
                        }
                    }
                    if (athDesc.IsExpCol == 1)
                        html += "<td><a href=\"\" onclick=\"return SaveUpload()\">保存</a><a href='javaScript:void(0)' onclick='changeSort(\"" + sort + "\")'>上传</a></td>";
                    else {
                        var explorer = window.navigator.userAgent;
                        var isIE = explorer.indexOf("compatible") > -1 && explorer.indexOf("MSIE") > -1; //判断是否IE<11浏览器
                        if (((explorer.indexOf('MSIE') >= 0) && (explorer.indexOf('Opera') < 0) || (explorer.indexOf('Trident') >= 0)))
                            html += "<td></td>";
                        else
                            html += "<td><a href='javaScript:void(0)' onclick='changeSort(\"" + sort + "\")'>上传</a></td>";
                    }
                    html += "</tr>";
                }
            }
            if ((i == 0 && (athDesc.Sort == null || athDesc.Sort.indexOf(",") == -1)) || (athDesc.IsExpCol == 1 && athDesc.IsUpload == true)) {
                html += "<tr>";
                html += "<td class='Idx' nowrap>*</td>"; ;

                if (athDesc.IsUpload == true)
                    html += "<td style='width:100px'> </td>";
                else
                    html += "<td style='width:100px'></td>";
                html += "<td>&nbsp&nbsp</td>";
                html += "<td>&nbsp&nbsp</td>";
                html += "<td>&nbsp&nbsp</td>";

                //如果有数据,就要解析它附件属性.
                if (athDesc.IsExpCol == 1) {

                    for (var ii = 0; ii < mapAttrs.length; ii++) {

                        html += "<td>" + InitAthMapAttrOfCtrlFool("", mapAttrs[ii]) + "</td>";
                    }
                }
                if (athDesc.IsExpCol == 1)
                    html += "<td><a href=\"\" onclick=\"return SaveUpload()\">保存</a></td>";
                else
                    html += "<td>&nbsp&nbsp</td>";
                html += "</tr>";
            }

            html += AddFileUpload(athDesc);
            html += "</tbody>";

            $("#ShowTable").html(html);


        }


        //增加文件名称
        function addTdTitle(title, str) {
            return "\n<td  nowrap title='" + title + "' >" + str + "</td>";
        }


        var realFileExts = "";
        function AddFileUpload(athDesc) {
            var html = "";
            if (athDesc.IsUpload == true && IsReadonly != "1") {
                html += "<tr>";
                if (athDesc.Sort != null && athDesc.Sort.indexOf(",") != -1)
                    html += "<td colspan=" + (columnNum + 1) + ">";
                else
                    html += "<td colspan=" + columnNum + ">";

                var explorer = window.navigator.userAgent;
                var isIE = explorer.indexOf("compatible") > -1 && explorer.indexOf("MSIE") > -1; //判断是否IE<11浏览器
                if (((explorer.indexOf('MSIE') >= 0) && (explorer.indexOf('Opera') < 0) || (explorer.indexOf('Trident') >= 0))) {

                    if (athDesc.Exts != null && athDesc.Exts != "") {
                        var fileExts = athDesc.Exts.replace(/,/g, ";");
                        var fileExtData = fileExts.split(';');

                        for (var i = 0; i < fileExtData.length; i++) {
                            var ext = fileExtData[i]
                            if (ext != null && ext != "") {
                                if (ext.indexOf("*.") == 0)
                                    realFileExts += ext + ";";
                                else
                                    realFileExts += "*." + ext + ";";
                            }
                        }
                    }

                    if (realFileExts == null || realFileExts == "")
                        realFileExts = "*.*";


                    html += "<div id='file_upload-queue' class='uploadify-queue'></div>";

                    if (athDesc.Sort != null && athDesc.Sort.indexOf(",") != -1) {
                        var sortColumn = athDesc.Sort.indexOf("@") != -1 ? athDesc.Sort.substring(0, athDesc.Sort.indexOf("@")) : "类别";
                        var strs = athDesc.Sort.indexOf("@") != -1 ? athDesc.Sort.substring(athDesc.Sort.lastIndexOf("@") + 1).split(',') : athDesc.Sort.split(',');
                        var operations = "";
                        for (var idx = 0; idx < strs.length; idx++) {
                            operations += "<option  value='" + strs[idx] + "'>" + strs[idx] + "</option>";
                        }
                        html += "<div id='s' style='text-align:right;float:left;display:inline;' >";
                        html += "<div style='float:left;padding-top:7px;padding-right:2px'>";
                        html += "请选择" + sortColumn + "：";
                        html += "<select id='Sort'>" + operations + "</select>";
                        html += "</div>";
                    }
                    else {
                        html += "<div id='s' style='text-align:right;float:right;display:inline;' >";
                    }
                    html += "<div style='float:left;margin-left:5px;'>";
                    html += "<input type='file' style='float:left' name='uploadfile' id='uploadfile' />";
                    html += "</div>";
                    html += "</div>";

                    if (athDesc.IsNote)
                        html += "<input type='text' id='TB_Note' style='width:90%;display:none;' size='30'/>";

                } else {
                    html += "<div id='s' style='text-align:right;float:left;display:inline;' >";
                    // 让石家庄客户，来完善附件类别支持sql.
                    if (athDesc.Sort != null && athDesc.Sort.indexOf(",") != -1) {
                        var sortColumn = athDesc.Sort.indexOf("@") != -1 ? athDesc.Sort.substring(0, athDesc.Sort.indexOf("@")) : "类别";
                        var strs = athDesc.Sort.indexOf("@") != -1 ? athDesc.Sort.substring(athDesc.Sort.lastIndexOf("@") + 1).split(',') : athDesc.Sort.split(',');
                        var operations = "";
                        for (var idx = 0; idx < strs.length; idx++) {
                            if (strs[idx] == "")
                                continue;
                            operations += "<option  value='" + strs[idx] + "'>" + strs[idx] + "</option>";
                        }

                        html += "<div style='float:left;padding-top:7px;padding-right:2px'>";
                        html += "请选择" + sortColumn + "：";
                        html += "<select id='Sort'>" + operations + "</select>";
                        html += "</div>";
                    }
                    html += "<div style='float:left;padding-top:7px;padding-right:2px'>";
                    if (athDesc.IsExpCol == 1)
                        html += "<input type='file' name='file' id='file' style='display:inline'  >"
                    else
                        html += "<input type='file' name='file' id='file' style='display:inline' onclick='return Upload();' onchange='UploadChange();'>"
                    if (athDesc.IsNote)
                        html += "<input type='text' id='TB_Note' style='width:90%;display:none;' size='30'/>";
                    html += "</div>";
                }
                html += "</div>";
                html += "</td>";
                html += "</tr>";
            }
            return html;
        }

        function changeSort(sort) {
            $("#Sort").val(sort);
            //激活上传文件
            $("#file").click();

        }

        //上传.
        function Upload() {

            try {

                if (OnUploadClick() == false)
                    return false;
            } catch (e) {
                //alert(e);
                //return;
            }
        }
        function SaveUpload() {

            //必填项和正则表达式检查
            var formCheckResult = true;

            if (checkBlanks() == false) {
                formCheckResult = false;
            }

            if (checkReg() == false) {
                formCheckResult = false;
            }

            if (formCheckResult == false) {
                alert("请检查表单必填项和正则表达式");
                return false;
            }

            var explorer = window.navigator.userAgent;
            var isIE = explorer.indexOf("compatible") > -1 && explorer.indexOf("MSIE") > -1; //判断是否IE<11浏览器
            if (((explorer.indexOf('MSIE') >= 0) && (explorer.indexOf('Opera') < 0) || (explorer.indexOf('Trident') >= 0))) {
                $('#uploadfile').uploadify("upload", "*");
                return;
            }

            UploadChange();
        }
        function UploadChange() {
            var fileObj = document.getElementById("file").files[0]; // js 获取文件对象
            if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
                alert("请选择上传的文件.");
                return;
            }
            //form表单序列话
            var parasData = $("form").serialize();
            //form表单序列化时调用了encodeURLComponent方法将数据编码了
            parasData = decodeURIComponent(parasData, true);
            parasData = decodeURIComponent(parasData, true);
            parasData = parasData.replace(/&/g, '@');
            parasData = parasData.replace(/TB_/g, '');
            parasData = parasData.replace(/RB_/g, '');
            parasData = parasData.replace(/CB_/g, '');
            parasData = parasData.replace(/DDL_/g, '');

            var formData = new FormData();
            var name = $("input").val();
            formData.append("file", fileObj);
            formData.append("name", name);
            var AttachPK = FK_FrmAttachment;
            var Url = "";
            if (plant == 'CCFlow')
                Url = "/WF/CCForm/Handler.ashx?DoType=MoreAttach&FK_FrmAttachment=" + FK_FrmAttachment + "&DoMethod=MoreAttach&HttpHandlerName=BP.WF.HttpHandler.WF_CCForm&WorkID=" + WorkID + "&PKVal=" + PKVal + "&AttachPK=" + AttachPK + "&parasData=" + parasData + "&t=" + new Date().getTime();
            else {
                var currentPath = window.document.location.href;
                var path = currentPath.substring(0, currentPath.indexOf('/WF') + 1);
                Url = path + "WF/Ath/AttachmentUploadS.do/?FK_FrmAttachment=" + FK_FrmAttachment + "&PKVal=" + PKVal + "&parasData=" + parasData;
            }

            Url += "&FID=" + GetQueryString("FID");
            Url += "&FK_Node=" + GetQueryString("FK_Node");
            Url += "&PWorkID=" + GetQueryString("PWorkID");
            Url += "&FK_MapData=" + GetQueryString("FK_MapData");
            //获取分组
            var sort = $("#Sort").val();
            if (sort != null && sort != "" && sort != undefined)
                Url += "&Sort=" + sort;


            $.ajax({
                url: Url,
                type: 'POST',
                data: formData,
                async: false,
                // 告诉jQuery不要去处理发送的数据
                processData: false,
                // 告诉jQuery不要去设置Content-Type请求头
                contentType: false,
                beforeSend: function () {
                    console.log("正在进行，请稍候");
                },
                success: function (responseStr) {

                    if (responseStr.indexOf('err@') != -1)
                        alert(responseStr);

                },
                error: function (responseStr) {
                    if (responseStr.indexOf('err@') != -1)
                        alert(responseStr);

                    console.log(responseStr);
                }
            });

            window.location.href = window.location.href;
        }
        function OpenOfiice(fk_ath, pkVal, delPKVal, FK_MapData, NoOfObj, FK_Node) {
            var date = new Date();
            var t = date.getFullYear() + "" + date.getMonth() + "" + date.getDay() + "" + date.getHours() + "" + date.getMinutes() + "" + date.getSeconds();
            var url = '../WebOffice/AttachOffice.aspx?DoType=EditOffice&DelPKVal=' + delPKVal + '&FK_FrmAttachment=' + fk_ath + '&PKVal=' + pkVal + "&FK_MapData=" + FK_MapData + "&NoOfObj=" + NoOfObj + "&FK_Node=" + FK_Node + "&T=" + t;
            window.open(url, '_blank', 'height=600,width=850,top=50,left=50,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no');
        }

        function OpenFileView(pkVal, delPKVal) {
            var url = 'FilesView.aspx?DoType=view&DelPKVal=' + delPKVal + '&PKVal=' + pkVal + '&FK_FrmAttachment=<%=FK_FrmAttachment %>&FK_FrmAttachmentExt=<%=FK_FrmAttachmentExt %>&FK_Flow=<%=FK_Flow %>&FK_Node=<%=FK_Node %>&WorkID=<%=WorkID %>&IsCC=<%=IsCC %>';
            window.open(url, '_blank', 'height=600,width=850,top=50,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no, status=no');
        }
        function OpenView(pkVal, delPKVal) {
            var url = 'FilesView.aspx?DoType=view&DelPKVal=' + delPKVal + '&PKVal=' + pkVal + '&FK_MapData=<%=FK_MapData %>&FK_FrmAttachment=<%=FK_FrmAttachment %>&FK_FrmAttachmentExt=<%=FK_FrmAttachmentExt %>&FK_Flow=<%=FK_Flow %>&FK_Node=<%=FK_Node %>&WorkID=<%=WorkID %>&IsCC=<%=IsCC %>';
            window.open(url, '_blank', 'height=600,width=850,top=50,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no, status=no');
        }
        // 上传Img.
        function UploadImg() {
            // window.(url, '_blank', 'height=600,width=850,top=50,left=50,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no');
            //window.location.href = 'AttachmentUploadImg.aspx?FK_FrmAttachment=' + fk_ath + '&PKVal=' + pkVal + '&FK_Node=<%=FK_Node %>&FK_Flow = <%=FK_Flow %>&FK_MapData=<%=FK_MapData %>&Ath=<%=Ath %>';
        }

        //关闭窗口  适用于扩展属性
        function close() {
            if (parent != undefined && parent.SetAth != undefined && typeof (parent.SetAth) == "function") {
                var nameTds = $('.Idx').next();
                var nameStrs = [];
                $.each(nameTds, function (i, nameTd) {
                    nameStrs.push($(nameTd).children('a').text());
                })
                parent.SetAth(nameStrs);
            }
        }
    </script>
</head>
<body>
    <form id="Ath_Form">
    <div id="Msg">
    </div>
    <div style="width: 99%">
        <table id="ShowTable" class="table">
        </table>
    </div>
    <div id="bar" style="display: none; position: fixed; bottom: 0px; right: 0px;">
        <button class="btn btn-info" id="btn_Colse" style="border: 0; background: #2884fa;
            color: #FFF; font-size: 12px; padding: 6px 10px; border-radius: 15px; margin: 5px;">
            关闭</button>
    </div>
    </form>
    <iframe width='0' height='0' frameborder='0' name="hrong" style="display: none">
    </iframe>
</body>
</html>
